import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;

/**
 * Responsible for the display of {@link Card} objects.
 * 
 * @author William Jarman
 * @author Ricky Vincent
 */
public class CardView {

	private static PlayerModel model;
	private static final double shadow = 1;
	
	/**
	 * Sets the {@link Model}
	 * 
	 * @param m
	 */
	public static void setModel(PlayerModel m) {
		model = m;
	}
	
	/**
	 * Draws a {@link Card} image on the <code>Graphics2D</code> object passed in.
	 * 
	 * @param g2d The <code>Graphics2D</code> to draw on.
	 * @param card The <code>Card</code> object to draw.
	 * @param listen The <code>ImageObserver</code> that will be notified of changes to the image. 
	 */
	public static void draw(Graphics2D g2d, Card card, JPanel listen){
		
		int x = (int)card.getLocation().getX();
		int y = (int)card.getLocation().getY();
	
		AffineTransform at = new AffineTransform();
		at.setToTranslation(x,y);
		
		g2d.drawImage(card.getImage(), at, listen);
		
		//draw the selection rectangle
		if (model.isSelectedCard(card)) {
			g2d.setColor(Color.green);
			g2d.draw(card.getRectangle());
		}
	}
	
	public static void drawShadow(Graphics2D g2d, Card card, JPanel listen){
		
		int x = (int)card.getLocation().getX();
		int y = (int)card.getLocation().getY();
	
		
		int cardZ = (int)(card.getZ());
		cardZ--;
		if(cardZ > 0) {
			cardZ = (int)((cardZ + 8)/10);
		}
		
		Rectangle rect = new Rectangle(card.getRectangle());
		rect.translate((int)(- cardZ * shadow),(int)(- cardZ * shadow));
		g2d.setColor(Color.black);
		g2d.fill(rect);
		
		//AffineTransform at = new AffineTransform();
		//at.setToTranslation(x + cardZ,y + cardZ);
		//g2d.drawImage(card.getImage(), at2, listen);
	}
}
